<?php

declare (strict_types = 1);

namespace app\mini\controller;



use app\BaseController;

use think\facade\Cache;

use think\facade\Db;

use app\admin\model\File as FileModel;





/**

 * Class Index

 * @package app\mini\controller

 */

class File extends BaseController

{

	/**

     * 附件上传

     * @return

     */

    public function save()

    {

      // print_r(1);exit();

        $files    = request()->file('file');

       // $files     = request()->file('img');

        # 项目上传附件权限

        /*

        if (!empty($this->param['module']) && $this->param['module'] == 'work_task' && !empty($this->param['work_id'])) {

            if (!$this->checkWorkOperationAuth('uploadTaskFile', $this->param['work_id'], $this->userInfo['id'])) {

                header('Content-Type:application/json; charset=utf-8');

                exit(json_encode(['code' => 102, 'error' => '无权操作！']));

            }

        }

        */

        $fileModel = new FileModel();

        // $param = $this->param;

        $param = [];

        $param['create_user_id'] = 0;

        // $ext = $files->getOriginalExtension();

        // if (in_array($ext, ['xlsx', 'xls', 'csv'])) {

        //     $res = $fileModel->excelData($files, $param);

        // } else {

            $res = $fileModel->createData($files, $param);

        // }



        if($res){

            return resultArray(['data' => $res]);

        } else {

            return resultArray(['error' => $fileModel->getError()]);

        }



    }


    public function bannerFile()
    {
        $files    = request()->file('file');

        // var_dump($files);

        $fileModel = new FileModel();

        $param = [];

        $param['create_user_id'] = 0;
        
        $res = $fileModel->uploadBanner($files, $param);

        if($res){

            return resultArray(['data' => $res]);

        } else {

            return resultArray(['error' => $fileModel->getError()]);

        }

        
    }


}

